
//
//  ViewController.m
//  JinChengYun
//
//  Created by 金橙云 on 2017/2/24.
//  Copyright © 2017年 金橙云. All rights reserved.
//

#import "ViewController.h"


#import "UIButton+ImageTitleSpacing.h"
#import "Masonry.h"
#import "LoginViewController.h"
@interface ViewController ()

@end

@implementation ViewController

-(void)viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBarHidden = YES;
}

-(void)viewDidDisappear:(BOOL)animated
{
   self.navigationController.navigationBarHidden = NO;
}
- (void)viewDidLoad {
    [super viewDidLoad];
  
    // 防止block中的循环引用
    //__weak typeof (self) weakSelf = self;
    UIView *bgView = [[UIView alloc] init];
    bgView.frame =CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
    bgView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"first_bg"]];
    
    [self.view addSubview:bgView];

    
    UIImageView *imageView = [[UIImageView alloc] init];
   // imageView.frame = CGRectMake(30, 70, 300, 70);
    imageView.image = [UIImage imageNamed:@"LOGO11"];
     [bgView addSubview:imageView];
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(270, 50));
        make.centerX.mas_equalTo(bgView);
        make.top.mas_equalTo(bgView.mas_centerY).offset(-260);
       
        
    }];
   
    
    //ceo
    UIButton *ceoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [ceoBtn setBackgroundImage:[UIImage imageNamed:@"ceo6"] forState:0];
   // ceoBtn.backgroundColor = [UIColor redColor];
    [ceoBtn setTitle:@"ceo" forState:0];
    [ceoBtn layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleTop imageTitleSpace:250];
    ceoBtn.layer.cornerRadius = 50.f;
    [ceoBtn addTarget:self action:@selector(ceoBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    ceoBtn.tag = 3;
    [bgView addSubview:ceoBtn];
    [ceoBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(100);
        make.top.equalTo(imageView.mas_bottom).offset(30);
        make.centerX.equalTo(bgView);
        
    }];
                       
    
    //经理
    UIButton *jingBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [jingBtn setBackgroundImage:[UIImage imageNamed:@"jingLi"] forState:0];
    [jingBtn setTitle:@"销售经理" forState:0];
    [jingBtn layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleTop imageTitleSpace:270];
    jingBtn.layer.cornerRadius = 50.f;
    [jingBtn addTarget:self action:@selector(ceoBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    jingBtn.tag = 2;
    [bgView addSubview:jingBtn];
    [jingBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(100);
        make.top.equalTo(ceoBtn.mas_bottom).offset(60);
        make.left.equalTo(ceoBtn.mas_left).offset(-90);
    }];
    
    //置业顾问
    UIButton *zhiBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    //zhiBtn.backgroundColor = [UIColor redColor];
    [zhiBtn setBackgroundImage:[UIImage imageNamed:@"zygw"] forState:0];
    [zhiBtn setTitle:@"置业顾问" forState:0];
    zhiBtn.layer.cornerRadius = 50.f;
    [zhiBtn layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleTop imageTitleSpace:270];
    [zhiBtn addTarget:self action:@selector(ceoBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    zhiBtn.tag = 1;
    [bgView addSubview:zhiBtn];
    [zhiBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(100);
        make.left.equalTo(jingBtn.mas_right).offset(80);
        make.top.equalTo(ceoBtn.mas_bottom).offset(60);
    }];
    
    
}

-(void)ceoBtnClick:(UIButton *)btn
{
    NSString *tagSt = [NSString stringWithFormat:@"%ld",(long)btn.tag];
  
   
    //CEO
    if (btn.tag == 3)
    {
        NSUserDefaults *userDefa = [NSUserDefaults standardUserDefaults];
        [userDefa setObject:@"3" forKey:@"STATE"];
        [userDefa setObject:tagSt forKey:@"BTG"];
        NSLog(@"--------TAG 值-----%@",tagSt);
        [userDefa synchronize];

        LoginViewController *loginVC = [[LoginViewController alloc] init];
//        loginVC.userStr = @"zongjingli1";
//        loginVC.passwStr = @"zongjingli1";
        [self presentViewController:loginVC animated:NO completion:nil];
    }
    //j经理
    else if (btn.tag ==2)
    {
        NSUserDefaults *userDefa = [NSUserDefaults standardUserDefaults];
        [userDefa setObject:@"2" forKey:@"STATE"];
        [userDefa setObject:tagSt forKey:@"BTG"];
        NSLog(@"--------TAG 值-----%@",tagSt);
        [userDefa synchronize];
        LoginViewController *loginVC = [[LoginViewController alloc] init];
//        loginVC.userStr = @"jingli";
//        loginVC.passwStr = @"jingli";
        [self presentViewController:loginVC animated:NO completion:nil];
    }
    else //置业顾问
    {
        NSUserDefaults *userDefa = [NSUserDefaults standardUserDefaults];
        [userDefa setObject:@"1" forKey:@"STATE"];
         [userDefa setObject:tagSt forKey:@"BTG"];
        NSLog(@"--------TAG 值-----%@",tagSt);
        [userDefa synchronize];
        LoginViewController *loginVC = [[LoginViewController alloc] init];
//        loginVC.userStr = @"guwen";
//        loginVC.passwStr = @"guwen";
        [self presentViewController:loginVC animated:NO completion:nil];
    }
   
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
